import { RequestHandler, urlencoded } from "express";
import { z } from "zod";


const handler: RequestHandler = async (req, res, next) => {
    const input = z.object({
        state: z.string()
    })
    const body = input.parse(req.query)
    const authHost = process.env.AUTH_HOST
    const authAppId = process.env.AUTH_APPID
    const siteHost = process.env.SITE_HOST
    const redirect_uri = encodeURI(`${siteHost}/sso/token`)
    const url = `${authHost}/oauth/authorize?response_type=code&client_id=${authAppId}&redirect_uri=${redirect_uri}&state=${body.state}`
    res.redirect(url)
}
export default handler;